%% TODO: rewrite to only be reed-solomon?
%% or just accept the FEC labeling.

\subsection{Forward Error Correction}

\label{sec:fec}
\begin{description}
	\item[Estimated gates] 2000
	\item[Estimated data bitstream delay] Slightly more than $frac{N_{cbps}}{2} + 8$
\end{description}

This is a Reed-Solomon and convolution coding combination
which is applied per frame. Within the standard, different
RS (Reed-Solomon) codes and CC (convolution code) rates are
used for varying modulation types. As we have fixed the
modulation and code rate to QPSK-1/2, one two of the RS
code and CC rate pairs are needed, as indicated in the
\autoref{tbl:fec-param}.

See \autoref{tbl:fec-io} for a listing of the inputs and outputs.

\subsubsection{Notes on delay}

Both the Reed-Solomon and convolution encoding append additional bits to the bitstream. The convolution encoder emits at most 2 bits for every one bit of input (the 1/2 rate, used with BPSK). The Reed-Solomon encoder appends the residue of its operation to the tail of the bitstream. As it operates of $GF(8)$, 8 bits will be appended. Additionally, between the RS and CC additional bits are appended to such that the bitstream is kept at a multiple of $N_{cbps}$ bytes.

\begin{table*}
	\begin{tabularx}{\linewidth}{X|X|X|X|X|X}
	\label{tbl:fec-param}
		Modulation & Uncoded block size (bytes) &
		Coded block size (bytes) & Overall coding
		rate & RS code & CC code rate \\ \hline
		QPSK & 24 & 48 & 1/2 & (32,24,4) & 2/3 \\
	\end{tabularx}
	\caption{Forward Error correction rates}
\end{table*}

\begin{table*} \begin{tabularx}{\linewidth}{c|c|c|X}
	\label{tbl:fec-io}
	Name & Width & Direction & Description \\ \hline

	\wire{reset} & 1 & I & Active low, resets logic block to initial
	state. \\

	\wire{clk}   & 1 & I & Clocking. \\

	\wire{in\_bits} & 1 & I & Input bitstream, processed by randomizer.
	\\

	\wire{in\_valid} & 1 & I & Indicates the input bitstream
	\wire{in\_bits} should be read.\\

	\wire{out\_bits} & 1 & O & Output bitstream, has FEC
	applied. Will be longer than input bitstream. \\

	\wire{out\_valid} & 1 & O & Indicates the output bitstream
	is valid (the data on it should be read and processed) \\

	\wire{rate\_id} & 3 & I & The type of modulation used. See
	\autoref{tbl:rate-id} for possible values.

\end{tabularx} \caption{FEC interface description} \end{table*}
